var BASE = "remote.php";

function reloadControls() {
  removeControls();
  sendMsg("GetCommands", "showCommands");
  loadResetHost();
}

function removeControls() {
  var el = $('mainList');
  while (el.childNodes.length > 0) {
    el.removeChild(el.childNodes[0]);
  }
}

function newFunction(_cmd) {
  var cmd = _cmd;
  return function() {
    sendMsg("Command", "_null", { command: cmd });
  };
}

function showCommands(msg) {
  removeControls();
  var cmds = msg.split(/\|/);
  for (var i=0; i<cmds.length; i++) {
    var cmd = cmds[i];
    var a = newLi(cmd);
    a.href = "#";
    a.onclick = newFunction(cmd);
  }
  loadResetHost();
}

function onLoad() {
  reloadControls();
}
